<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<%@ include file="/pub/head_bootstrap.inc"%>
	<c:set var="basePageTitle" value="${sessionScope.logoName}"	scope="request" />
	<title>${logoName}</title>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
	<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
	<meta name="description" content="User login page" />
	<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
	<c:set var="baseURL" value="http://${header.host}${pageContext.request.contextPath}" scope="request" />
	<script type="text/javascript">
		var baseURL = "${baseURL}";
	</script>
	<link rel="stylesheet" href="${baseURL}/web/css/style.css" />
	<link href="${baseURL}/themes/blue/css/fonts/iconfont.css" rel="stylesheet" type="text/css" />
	<LINK href="logo.png?v=1" type="image/x-icon" rel="shortcut icon" />

	<script src="${baseURL}/js/jquerys/jquery-1.12.1.min.js" type="text/javascript"></script>
	<script src="${baseURL}/js/placeholder_IE.js" type="text/javascript"></script>
	<script type="text/javascript" src="${baseURL }/themes/plugin/aes/aes.js"></script>
	<script type="text/javascript" src="${baseURL }/themes/plugin/aes/pad-iso10126-min.js"></script>
	<script type="text/javascript" src="${baseURL }/themes/plugin/aes/aesUtil.js"></script>

	<style type="text/css">
		.user_type_btn {
			margin-top: 62px;
		}

		.enterprise_btn {
			margin-top: 41px;
		}

		.register-form {
			display: none;
		}

        .input-group-addon {
         padding: 0px;
        }
        .icon {
            height: 33px;
        }

        .login-content>.login-form {
            height: 380px;
        }

        .login-content {
            height: 380px;
        }
	</style>
</head>
<body>
	<div class="container">
        <div class="logo">
            <c:choose>
                <c:when test="${!empty systemName}">
                    <h1>${systemName}</h1>
                </c:when>
                <c:when test="${!empty loginLogo}">
                    <img src='${baseURL}/cfg/basedefineedit/downloadImgCache.do?tempId=${loginLogo}' />
                </c:when>

                <c:otherwise >
                    <img src="${baseURL}/images/index/logo.png" />
                </c:otherwise>
            </c:choose>

        </div>
	 
		<div class="login-content">
			<div class="login-form">
				<div class="title">用户注册</div>

				<div class="user_type_btn">
					<button type="button" class="blue-btn normal_btn">普通用户</button>
					<button type="button" class="blue-btn enterprise_btn">企业用户</button>
				</div>

				<form class="register-form">
					<input type="hidden" name="userType" id="userType"/>
					<div class="form-input">
						<span class="icon"><i class="icon iconfont icon-icon-user"></i></span>
						<input id="email" name="email" placeholder="输入邮箱" />
					</div>
					<div class="form-input">
						<span class="icon"><i class="icon iconfont icon-icon-unlock"></i></span>
						  <!-- 主要input需要放置最后,避免ie上无法兼容 -->
					 	  <input type="password" id="password" name="password" placeholder="输入密码" />
					</div>

					<div class="form-input">
						<span class="icon"><i class="icon iconfont icon-icon-unlock"></i></span>
						<!-- 主要input需要放置最后,避免ie上无法兼容 -->
						<input type="password" id="confirmPassword" name="confirmPassword" placeholder="请再次输入密码" />
					</div>

					<c:if test="${isVerify == 1}">
						<div class="validate_code">
							<div class="form-input">
								<span class="icon"><i class="icon iconfont icon-icon-shield"></i></span>
								<input type="text" id="codes" name="codes" style="height: 32px;" />
							</div>
							<span class="input-group-addon">
							<img class="validate_img" onclick="changeCode();" >
						</span>
						</div>
					</c:if>

					<div class="margin-20">
						<button type="button" class="blue-btn" id="register" style="margin-bottom: 20px;">注册</button>
					</div>
				</form>
			</div>
		</div>
	</div>
	<div class="footer">
		<p>
		<c:if test="${empty icp}">
		CopyRight©广州八斗软件科技有限公司  All Rights Reserved
		</c:if>
		<c:if test="${!empty icp}">
		${icp}
		</c:if>
		</p>
	</div>
	<script type="text/javascript">
	//浏览器识别
	function myBrowser() {
		var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串
		var isOpera = userAgent.indexOf("Opera") > -1; //判断是否Opera浏览器
		//var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1 && !isOpera; //判断是否IE浏览器
		var isIE = !!window.ActiveXObject || "ActiveXObject" in window; //判断是否IE浏览器
		var isFF = userAgent.indexOf("Firefox") > -1; //判断是否Firefox浏览器
		var isSafari = userAgent.indexOf("Safari") > -1; //判断是否Safari浏览器
		var isChrome = userAgent.indexOf("Chrome") > -1; //判断是否谷歌浏览器
		var isSafari = userAgent.indexOf("Safari") > -1; //判断是否Safari浏览器
		var is360 = userAgent.indexOf("360SE") > -1; //判断是否360浏览器
		var isEdge = userAgent.indexOf("Edge") > -1 && !isIE; //判断是否IE的Edge浏览器  
		if (isIE) {
			var reIE = new RegExp("MSIE (\\d+\\.\\d+);");
			reIE.test(userAgent);
			var fIEVersion = parseFloat(RegExp["$1"]);
			//9.0以上才返回true
			if (fIEVersion >= 9) {
				return true;
			} else {
				//如果这里获取不到fIEVersion，证明是ie11,所以也返回true
				if (!fIEVersion)
					return true;
				return false;
			}
		}//isIE end
		if(isEdge){
			return true;
		}//isEdge end
		if (isFF) {
			return true;
		}
		/* if (isOpera) {
		    return true;
		} */
		if (isChrome) {
			return true;
		}
		if (is360) {
			return true;
		}
		if (isSafari) {
			return true;
		}
		return false;
	}//myBrowser() end

	//判断浏览器是否符合兼容性，不符合就跳转页面
	if (!myBrowser()) {
		window.location.href = "${baseURL}/change_browser.jsp";
	}
	
		$(function() {
			$(document).keypress(function(event) {
				if (event.keyCode == 13) { // 13表示回车键
					$("#submitForm").click();
					return false;
				}
			});
			changeCode();
			<c:if test="${!empty loginBackground}">
			$(".container").css("background","url(${baseURL}/cfg/basedefineedit/downloadImgCache.do?tempId=${loginBackground})")
			</c:if>

			$('.normal_btn').click(function () {
                showForm(1)
            })

            $('.enterprise_btn').click(function () {
                showForm(2)
            })
		});


		$("#register").click(function() {
			// enCode();


			var email = $("#email").val().trim()
			var password = $("#password").val()
			var confirmPassword = $("#confirmPassword").val()
			
			if (email == '') {
			    BT.showWarning('请输入邮箱！')
				return false
			}

			// TODO 判断email格式是否正确
			var reg = /^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z0-9]{2,6}$/
			if (!reg.test(email)) {
                BT.showWarning('请输入正确的邮箱地址！')
                return false
			}

			if (password == '') {
				BT.showWarning('请输入密码！')
				return false
			}

			if (confirmPassword == '') {
			    BT.showWarning('请再次输入密码！')
				return false
			}

			if (password != confirmPassword) {
                BT.showWarning('两次输入的密码不一致！')
                return false
			}

			// TODO 验证验证码

			var param = {email: email, password: password, userType: $('#userType').val()}

            param = aesEncrypt(JSON2.stringify(param))

            $.ajax({
                url: baseURL + '/system/security/userregister/create.do',
                type: 'post',
                data: {data: param},
                dataType: 'json',
                success: function(resp) {
                    if (resp.hasOk) {
                        BT.showSuccess("注册成功！", function () {
                            window.location.href = "${baseURL}/logon.jsp";
                        })
					} else {
                        BT.showError("注册失败！" + resp.message)
					}
                },
                error: function() {
                    BT.showError("服务器出现错误！")
                }
            })

		});

		String.prototype.trim = function() {
			return this.replace(/(^\s+)|\s+$/g, "");
		}
		
		//点击图片更换验证码
		function changeCode(){
			$(".validate_img").attr("src","${baseURL}/validate/yzmcode/validate.do?date="+new Date())
		}
		
		function validateCode(obj,errorObj,callback){
			$.ajax({
				type: "post",
			 		async: true,
				url: "${baseURL}/validate/checkcode/checkCode.do",
				dataType:"json",
				data:{codes:$(obj).val()},
		        async: false,
		        success: function(data){
		        	if(data){
		        		if(data.hasOk){
		            		if(callback){
		            			callback();
		            		}
		        		}else{
		        			$(errorObj).text("验证码不正确！");
		            		return false;
		        		}
		        	}
		        }
		    });
		}

		function showForm(userType) {
		    $('#userType').val(userType)
			$('.user_type_btn').hide()
			$('.register-form').show()
		}
	</script>
</body>
</html>